﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.Services;
using System.Collections;
using Catering.View_Operaction;

namespace Catering.Catering_Page.richang
{
    public partial class rbgl : UserIsNull
    {
        public string m_UserID = "0";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] != null) m_UserID = Session["UserID"].ToString();
            if (!IsPostBack)
            {
                this.LoadDrop();
                this.LoadRepRenYuan();
                //this.Txt_Tianbiaoren.Text = Session["User"].ToString();
                Txt_data.Attributes.Add("onfocus", "WdatePicker({dateFmt:'yyyy/MM/dd'})");

                btn_Search_Click(null, null);


            }
        }

        //公用的DropDownList绑定方法
        public void DropBind(DropDownList drop, DataTable dt, string strValue, string strText)
        {
            drop.Items.Clear();
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ListItem item = new ListItem();
                    item.Text = dt.Rows[i][strText].ToString();
                    item.Value = dt.Rows[i][strValue].ToString();
                    drop.Items.Add(item);
                }
            }
        }

        protected void LoadDrop()
        {
            string userid = Session["PersonnelID"].ToString();
            int companyid = 0;
            int groupid = 0;
            int classid = 0;
            bool isAdmin = false;
            Bind_Data_to_Controls.GetCompanyByCurrentUser(userid, out companyid, out groupid, out classid, out isAdmin);
            Bind_Data_to_Controls.Bind_Area_ddl(Drop_ZuoYeQu, isAdmin, groupid, companyid, false);
            Bind_Data_to_Controls.Bind_Class_ddl(Drop_ZuoYeQu.SelectedItem, Drop_BanZu, isAdmin, classid, false);

            if (Session["RBGropuID"] != null) this.Drop_ZuoYeQu.SelectedValue = Session["RBGropuID"].ToString();
            if (Session["RBClassID"] != null) this.Drop_BanZu.SelectedValue = Session["RBClassID"].ToString();
            if (!isAdmin)
            {
                this.Drop_ZuoYeQu.Enabled = false;
                this.Drop_BanZu.Enabled = false;
            }

            this.Txt_data.Text = DateTime.Now.ToShortDateString();
            if (Session["RBDate"] != null)
            {
                this.Txt_data.Text = Session["RBDate"].ToString();
            }
            Session.Remove("RBGropuID");
            Session.Remove("RBClassID");
            Session.Remove("RBDate");
        }

        protected void LoadRepRenYuan()
        {
            string ClassID = this.Drop_BanZu.SelectedValue;
            DataTable dt_RenYuan = new Catering_Rules.T_Personnel().GetList("ClassID=" + ClassID + " ORDER BY CASE WHEN PID=13 THEN 0 ELSE 1 END, CASE WHEN PID=14 THEN 0 ELSE 1 END, PID ").Tables[0];
            this.Rep_PeiCanRenYuan.DataSource = dt_RenYuan;
            this.Rep_PeiCanRenYuan.DataBind();
        }

        protected void Drop_ZuoYeQu_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt_BanZu = new Catering_Rules.ClassInfo().GetList("AreaID=" + this.Drop_ZuoYeQu.SelectedValue).Tables[0];
            this.DropBind(this.Drop_BanZu, dt_BanZu, "id", "CName");
            this.LoadRepRenYuan();
        }

        protected void Drop_BanZu_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.LoadRepRenYuan();
            //绑定下拉框
            ddl_moon.Items.Clear();
            List<Catering_Model.Moon> listmoon = new Catering_Rules.Moon().GetModelList(" ClassId = " + Drop_BanZu.SelectedValue);
            foreach (var item in listmoon)
            {
                ListItem li = new ListItem(item.MoonName, item.Id.ToString());
                ddl_moon.Items.Add(li);
            }
        }

        //保存日常管理信息
        [WebMethod]
        public static string Save_DailyManagement(string banzuID, string strdate, string gwgz, string fwzl, string wxyy, string wxjg, string dingyuan, string renyuancount, string strnumList, string SecurityRisks, string dishtest, string userid)
        {
            new Catering_Rules.DailyManagement().DeleteListBywhere("Date='" + Convert.ToDateTime(strdate).ToString() + "' and ClassID=" + banzuID);
            string[] svalue = strnumList.TrimEnd('|').Split('|');
            int qidwrenshu = 0;//其他单位人数
            for (int i = 0; i < svalue.Length; i++)
            {
                if (!string.IsNullOrEmpty(svalue[i])) qidwrenshu += Convert.ToInt32(svalue[i]);
            }
            Catering_Model.DailyManagement md = new Catering_Model.DailyManagement();
            int indy = 0;
            Int32.TryParse(dingyuan, out indy);
            md.ClassID = Convert.ToInt32(banzuID);
            md.CName = new Catering_Rules.ClassInfo().GetModel(Convert.ToInt32(banzuID)).CName;
            md.Date = Convert.ToDateTime(strdate);
            md.RID = Convert.ToInt32(userid);//需要获取当前登陆人
            md.Service = gwgz;
            md.Quality = fwzl;
            md.Repair = wxyy;
            md.temp1 = wxjg;
            //md.ContractorInfo = ChengBS;
            if (!string.IsNullOrEmpty(SecurityRisks)) md.temp2 = SecurityRisks;
            if (!string.IsNullOrEmpty(dishtest)) md.DishTest = dishtest;
            md.DetermineNumber = indy;
            //人员总数=定员+其他单位人数
            md.PNumber = md.DetermineNumber + qidwrenshu;
            new Catering_Rules.DailyManagement().Add(md, true);
            return "OK";
        }

        //保存考情信息
        [WebMethod]
        public static string Save_AttendanceRecord(string strID, string strdate, string ClassID, string GuanShi, string AnQuan)
        {
            new Catering_Rules.AttendanceRecord().DeleteListBywhere("Date='" + Convert.ToDateTime(strdate).ToString() + "' and ClassID=" + ClassID);
            DataTable dt = new Catering_Rules.T_Personnel().GetList(" ClassID=" + ClassID + " ").Tables[0];
            string[] SID = strID.TrimEnd('|').Split('|');
            ArrayList AddSID = new ArrayList();
            foreach (string s in SID)
            {
                if (AddSID.Contains(s)) continue;
                if (string.IsNullOrEmpty(s)) continue;
                Catering_Model.AttendanceRecord md = new Catering_Model.AttendanceRecord();
                md.Date = Convert.ToDateTime(strdate);
                md.ClassID = Convert.ToInt32(ClassID);
                md.PID = Convert.ToInt32(s);
                md.PName = new Catering_Rules.T_Personnel().GetModel(Convert.ToInt32(s)).Name;
                md.State = "1";
                if (GuanShi == s) md.temp1 = "1";
                if (AnQuan == s) md.temp2 = "1";
                new Catering_Rules.AttendanceRecord().Add(md);
                AddSID.Add(s);
            }

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string pid = dt.Rows[i]["ID"].ToString();
                    string Name = dt.Rows[i]["Name"].ToString();
                    if (SID.Contains(pid)) continue;
                    Catering_Model.AttendanceRecord md = new Catering_Model.AttendanceRecord();
                    md.Date = Convert.ToDateTime(strdate);
                    md.ClassID = Convert.ToInt32(ClassID);
                    md.PID = Convert.ToInt32(pid);
                    md.PName = Name;
                    md.State = "0";
                    new Catering_Rules.AttendanceRecord().Add(md);
                }
                dt.Dispose();
            }
            return "OK";
        }

        //保存人员动态信息
        [WebMethod]
        public static string Save_Dynamic(string GroupID, string ClassID, string strdate, string persons, string Number, string strID)
        {
            new Catering_Rules.Dynamic().DeleteListBywhere("Date='" + Convert.ToDateTime(strdate).ToString() + "' and ClassID=" + ClassID);
            string[] svalue = Number.TrimEnd('|').Split('|');
            string[] SID = strID.TrimEnd('|').Split('|');
            int qidwrenshu = 0;//其他单位人数
            for (int i = 0; i < svalue.Length; i++)
            {
                if (!string.IsNullOrEmpty(svalue[i])) qidwrenshu += Convert.ToInt32(svalue[i]);
            }
            ArrayList AddSID = new ArrayList();
            foreach (string s in SID)
            {
                if (string.IsNullOrEmpty(s.Trim())) continue;
                if (AddSID.Contains(s)) continue;
                AddSID.Add(s);
            }
            int dy = 0;
            Int32.TryParse(persons, out dy);
            Catering_Model.Dynamic md = new Catering_Model.Dynamic();
            md.GroupID = Convert.ToInt32(GroupID);//作业区
            md.ClassID = Convert.ToInt32(ClassID);//班组
            md.Date = Convert.ToDateTime(strdate);//时间
            md.persons = Convert.ToInt32(dy);//定员
            md.QC = qidwrenshu;//其他单位人数(外来单位人员)
            md.Catering = AddSID.Count;//配餐人数
            md.Number = md.persons + qidwrenshu + md.Catering;//人员总数=定员+其他单位人数+配餐人数
            md.Eat = md.Catering + md.QC;//就餐人数
            new Catering_Rules.Dynamic().Add(md, true);
            return "OK";
        }

        //保存服务人员动态信息
        [WebMethod]
        public static string Save_Dynamics(string GroupID, string ClassID, string strdate, string strtyepList, string strnumList, string strrageList)
        {
            new Catering_Rules.Dynamics().DeleteListBywhere("Dates='" + Convert.ToDateTime(strdate).ToShortDateString() + "' and ClassID=" + ClassID);
            string[] stype = strtyepList.TrimEnd('|').Split('|');
            string[] svalue = strnumList.TrimEnd('|').Split('|');
            string[] ragealue = strrageList.TrimEnd('|').Split('|');
            for (int i = 0; i < stype.Length; i++)
            {
                if (string.IsNullOrEmpty(stype[i])) continue;
                if (string.IsNullOrEmpty(svalue[i])) continue;
                Catering_Model.Dynamics md = new Catering_Model.Dynamics();
                md.GroupID = Convert.ToInt32(GroupID);
                md.ClassID = Convert.ToInt32(ClassID);
                md.Dates = Convert.ToDateTime(strdate);
                md.SpecialRate = 0;
                if (ragealue.Count() > i && !string.IsNullOrEmpty(ragealue[i]))
                {
                    decimal rate = 0;
                    Decimal.TryParse(ragealue[i], out rate);
                    md.SpecialRate = rate;
                }
                md.temp1 = stype[i];
                //md.EatTID = Convert.ToInt32(stype[i]);
                md.Eat = Convert.ToInt32(svalue[i]);
                new Catering_Rules.Dynamics().Add(md, true);
            }

            return "OK";
        }

        [WebMethod]
        public static string Save_ChengBaoShang(string GroupID, string ClassID, string strdate, string idlist, string strtextList)
        {
            new Catering_Rules.ContractorDailyMangement().DeleteListBywhere("WHERE DTime='" + Convert.ToDateTime(strdate).ToShortDateString() + "' and ClassID=" + ClassID + " and GroupID=" + GroupID);

            string[] stype = idlist.TrimEnd('|').Split('|');
            string[] svalue = strtextList.Split('◎');
            for (int i = 0; i < stype.Length; i++)
            {
                if (string.IsNullOrEmpty(stype[i])) continue;
                if (string.IsNullOrEmpty(svalue[i])) continue;
                Catering_Model.ContractorDailyMangement md = new Catering_Model.ContractorDailyMangement();
                md.GroupID = Convert.ToInt32(GroupID);
                md.ClassID = Convert.ToInt32(ClassID);
                md.DTime = Convert.ToDateTime(strdate);
                md.CID = Convert.ToInt32(stype[i]);
                md.ContentDesc = svalue[i];
                new Catering_Rules.ContractorDailyMangement().Add(md);
            }
            return "OK";
        }

        //获取服务人员可选项列表
        public string GetFuWuOption(string selectedid = "")
        {
            StringBuilder sb = new StringBuilder();
            DataTable dt_DynamicType = new Catering_Rules.DynamicType().GetList("").Tables[0];
            if (dt_DynamicType != null && dt_DynamicType.Rows.Count > 0)
            {
                sb.Append("<select>");
                for (int i = 0; i < dt_DynamicType.Rows.Count; i++)
                {
                    if (selectedid == dt_DynamicType.Rows[i]["id"].ToString())
                    {
                        sb.Append("<option value=\"" + dt_DynamicType.Rows[i]["id"].ToString() + "\" selected=\"selected\">" + dt_DynamicType.Rows[i]["Name"].ToString() + "</option>");
                    }
                    else
                    {
                        sb.Append("<option value=\"" + dt_DynamicType.Rows[i]["id"].ToString() + "\">" + dt_DynamicType.Rows[i]["Name"].ToString() + "</option>");
                    }
                }
                sb.Append("</select>");
            }
            return sb.ToString();
        }

        //获取 配餐人员可选项列表
        public string GetPeiCanOption()
        {
            StringBuilder sb = new StringBuilder();
            DataTable dt_DynamicType = new Catering_Rules.T_Personnel().GetList("").Tables[0];
            if (dt_DynamicType != null && dt_DynamicType.Rows.Count > 0)
            {
                sb.Append("<select>");
                for (int i = 0; i < dt_DynamicType.Rows.Count; i++)
                {
                    sb.Append("<option value=\"" + dt_DynamicType.Rows[i]["id"].ToString() + "\">" + dt_DynamicType.Rows[i]["Name"].ToString() + "</option>");
                }
                sb.Append("</select>");
            }
            return sb.ToString();
        }

        /// <summary>
        /// 根据人员ID 获取岗位名称
        /// </summary>
        /// <param name="strID">人员ID</param>
        /// <returns></returns>
        public string GetGangWeiNameByPersonnelID(string strID)
        {
            if (!string.IsNullOrEmpty(strID))
            {
                Catering_Model.E_Personnel personnel = new Catering_Rules.T_Personnel().GetModel(Convert.ToInt32(strID));
                if (personnel != null && personnel.PID > 0)
                {
                    int pid = new Catering_Rules.T_Personnel().GetModel(Convert.ToInt32(strID)).PID;
                    Catering_Model.BranchPost md = new Catering_Rules.BranchPost().GetModel(pid);
                    return md != null ? md.Name : "&nbsp;";
                }
            }
            return "&nbsp;";
        }

        /// <summary>
        /// 根据岗位ID 获取岗位名称
        /// </summary>
        /// <param name="strID">岗位ID</param>
        /// <returns></returns>
        public string GetGangWeiNameByID(string strID)
        {
            if (!string.IsNullOrEmpty(strID))
            {
                Catering_Model.BranchPost md = new Catering_Rules.BranchPost().GetModel(Convert.ToInt32(strID));
                return md != null ? md.Name : "&nbsp;";
            }
            return "&nbsp;";
        }

        //验证日期内是否存在数据
        [WebMethod]
        public static string IsExists(string strdate, string ClassID)
        {
            DataTable dt = new Catering_Rules.DailyManagement().GetList("Date='" + Convert.ToDateTime(strdate).ToString() + "' and ClassID=" + ClassID).Tables[0];
            return (dt != null && dt.Rows.Count > 0) ? "OK" : "NO";
        }

        //根据条件查询查询
        protected void btn_Search_Click(object sender, EventArgs e)
        {
            this.cbslist.InnerHtml = "";
            string strDate = this.Txt_data.Text.Trim();
            if (string.IsNullOrEmpty(strDate)) strDate = DateTime.Now.ToString("yyyy-MM-dd");
            DateTime data = DateTime.MinValue;
            DateTime.TryParse(strDate, out data);
            if (data > DateTime.MinValue)
            {
                string ClassID = this.Drop_BanZu.SelectedValue;
                string GroupID = this.Drop_ZuoYeQu.SelectedValue;
                SearchRB(GroupID, ClassID, data);
            }
        }

        private void SearchRB(string GroupID, string ClassID, DateTime data)
        {
            #region 初始化

            this.Rep_jiucan.DataSource = null;
            this.Rep_peican.DataSource = null;
            this.txt_dingyuan.Text = "";
            this.txt_renyuancount.Text = "";
            this.txt_wenti.Text = "";
            this.txt_zhiliang.Text = "";
            this.Txt_Tianbiaoren.Text = "";
            this.HF_Guanshi.Value = "";
            this.Lbl_Guanshi.Text = "";
            this.HF_AnQuan.Value = "";
            this.Lbl_AnQuan.Text = "";
            //this.txt_weixiuyuanying.Text = "";
            //this.txt_weixiujieguo.Text = "";
            //this.txt_anquanyinhuan.Text = "";

            #endregion

            Session["RBGropuID"] = GroupID;
            Session["RBClassID"] = ClassID;
            Session["RBDate"] = data.ToShortDateString();

            DataTable tempdt = new Catering_Rules.DailyManagement().GetList("Date='" + data.ToString() + "' and ClassID=" + ClassID).Tables[0];
            if (tempdt != null && tempdt.Rows.Count > 0)
            {
                int rid = Convert.ToInt32(tempdt.Rows[0]["RID"]);
                if (rid > 0)
                {
                    Catering_Model.E_Personnel md_person = new Catering_Rules.T_Personnel().GetModel(rid);
                    if (md_person != null) Txt_Tianbiaoren.Text = md_person.Name;
                }
            }

            DataTable dt_Dynamics = new Catering_Rules.Dynamics().GetList("GroupID=" + GroupID + " AND ClassID=" + ClassID + " AND Dates='" + data.ToShortDateString() + "'").Tables[0];
            this.Rep_jiucan.DataSource = dt_Dynamics;//服务人员
            this.Rep_jiucan.DataBind();

            DataTable dt_AttendanceRecord = new Catering_Rules.AttendanceRecord().GetList(" ClassID=" + ClassID + " AND Date='" + data.ToString() + "' AND State=1 ").Tables[0];
            this.Rep_peican.DataSource = dt_AttendanceRecord;//配餐在岗人员
            this.Rep_peican.DataBind();

            if (dt_AttendanceRecord != null && dt_AttendanceRecord.Rows.Count > 0)
            {
                DataRow[] drs = dt_AttendanceRecord.Select(" temp1='1' or temp2='1' ");
                foreach (DataRow item in drs)
                {
                    if (!(item["temp1"] is DBNull) && item["temp1"].ToString() == "1")
                    {
                        if (!(item["PName"] is DBNull) && item["PName"].ToString() != "" && !(item["PID"] is DBNull) && item["PID"].ToString() != "")
                        {
                            this.HF_Guanshi.Value = item["PID"].ToString();
                            this.Lbl_Guanshi.Text = item["PName"].ToString();
                        }
                    }
                    if (!(item["temp2"] is DBNull) && item["temp2"].ToString() == "1")
                    {
                        if (!(item["PName"] is DBNull) && item["PName"].ToString() != "" && !(item["PID"] is DBNull) && item["PID"].ToString() != "")
                        {
                            this.HF_AnQuan.Value = item["PID"].ToString();
                            this.Lbl_AnQuan.Text = item["PName"].ToString();
                        }
                    }
                }
                dt_AttendanceRecord.Dispose();
            }


            DataTable dt_Contractor = new Catering_Rules.ContractorDailyMangement().GetList(" ClassID=" + ClassID + " AND DTime='" + data.ToString() + "' ").Tables[0];
            if (dt_Contractor != null && dt_Contractor.Rows.Count > 0)
            {
                StringBuilder conlist = new StringBuilder();
                for (int i = 0; i < dt_Contractor.Rows.Count; i++)
                {
                    int cid = Convert.ToInt32(dt_Contractor.Rows[i]["CID"]);
                    string cname = "";
                    string context = dt_Contractor.Rows[i]["ContentDesc"].ToString();
                    Catering_Model.Contractor conmodel = new Catering_Rules.Contractor().GetModel(cid);
                    if (conmodel != null) cname = conmodel.CName;
                    conlist.Append("<table id='cbsTable_ID_" + (i + 1) + "'><tr>");
                    conlist.Append("<td><input class='input_bg' id='HF_Name_" + (i + 1) + "' name='HF_Name' readonly='readonly' value='" + cname + "'/>");
                    conlist.Append("<a href=\"javascript:ShowContractor('" + (i + 1) + "')\">选择承包商</a><input type='hidden' name='HF_ID' id='HF_ID_" + (i + 1) + "' value='" + cid + "' />");
                    conlist.Append("</td></tr><tr><td><textarea class='input_bg' id='HF_Text_" + (i + 1) + "' name='HF_Text' style=\"line-height:16px; width:469px; height:100px; \">" + context + "</textarea>");
                    conlist.Append("</td></tr><tr><td ><a href=\"javascript:delChengbaoshang('" + (i + 1) + "')\">删除</a></td></tr></table>");
                }
                dt_Contractor.Dispose();
                this.cbslist.InnerHtml = conlist.ToString();
            }

            DataTable dt_DailyManagement = new Catering_Rules.DailyManagement().GetList(" ClassID=" + ClassID + " AND Date='" + data.ToString() + "'").Tables[0];
            if (dt_DailyManagement == null || dt_DailyManagement.Rows.Count < 1)
            {
                return;
            }

            //定员等信息
            this.txt_dingyuan.Text = dt_DailyManagement.Rows[0]["DetermineNumber"].ToString();
            this.txt_renyuancount.Text = dt_DailyManagement.Rows[0]["PNumber"].ToString();
            this.txt_wenti.Text = dt_DailyManagement.Rows[0]["Service"].ToString();
            this.txt_zhiliang.Text = dt_DailyManagement.Rows[0]["Quality"].ToString();
            this.txt_weixiuyuanying.Text = dt_DailyManagement.Rows[0]["Repair"].ToString();
            this.txt_weixiujieguo.Text = dt_DailyManagement.Rows[0]["temp1"].ToString();
            this.txt_anquanyinhuan.Text = dt_DailyManagement.Rows[0]["temp2"].ToString();
            this.txt_dishtest.Text = dt_DailyManagement.Rows[0]["DishTest"].ToString();
        }

        /// <summary>
        /// 删除日报管理
        /// </summary>
        /// <param name="strdate"></param>
        /// <param name="ClassID"></param>
        /// <returns></returns>
        [WebMethod]
        public static string DeleteRiBao(string strdate, string ClassID)
        {
            int intclass = 0;
            DateTime date = DateTime.MinValue;
            DateTime.TryParse(strdate, out date);
            Int32.TryParse(ClassID, out intclass);
            if (date == DateTime.MinValue || intclass <= 0) return "NO";


            //服务人员
            string delclause = " ClassID=" + intclass + " AND Dates='" + date.ToString() + "' ";
            new Catering_Rules.Dynamics().DeleteListBywhere(delclause);
            //定员
            delclause = " ClassID=" + intclass + " AND Date='" + date.ToString() + "' ";
            new Catering_Rules.Dynamic().DeleteListBywhere(delclause);
            //考勤
            new Catering_Rules.AttendanceRecord().DeleteListBywhere(delclause);
            //日常管理信息
            new Catering_Rules.DailyManagement().DeleteListBywhere(delclause);
            return "OK";
        }

        /// <summary>
        /// 查找承包商信息
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public static string SearchConTractorList(string CName, string TagID, string CTime)
        {
            DataTable dt_Contractor = new DataTable();
            StringBuilder result = new StringBuilder("");
            if (!string.IsNullOrEmpty(CName))
            {
                dt_Contractor = new Catering_Rules.Contractor().GetList("CName like '%" + CName + "%'").Tables[0];
            }
            else
            {
                dt_Contractor = new Catering_Rules.Contractor().GetAllList().Tables[0];
            }
            DateTime date = DateTime.Now;
            if (!string.IsNullOrEmpty(CTime)) DateTime.TryParse(CTime, out date);

            result.Append("<table width='533' border='1' bordercolor='#CDDEF8' cellpadding='0' cellspacing='0'><tr><th width='20%'>承包商名称</th>");
            result.Append("<th width='10%'>联系人</th>");
            result.Append("<th width='12%'>联系电话</th>");
            result.Append("<th width='20%'>地址</th>");
            result.Append("<th width='8%'>状态</th>");
            result.Append("<th width='30%'>评价或说明</th>");
            result.Append("</tr>");

            if (dt_Contractor != null && dt_Contractor.Rows.Count > 0)
            {
                for (int i = 0; i < dt_Contractor.Rows.Count; i++)
                {
                    int id = Convert.ToInt32(dt_Contractor.Rows[i]["ID"]);
                    string name = dt_Contractor.Rows[i]["CName"].ToString();
                    string linkid = dt_Contractor.Rows[i]["LinkId"].ToString();
                    string Tel = dt_Contractor.Rows[i]["Tel"].ToString();
                    string Add = dt_Contractor.Rows[i]["Add"].ToString();
                    //string State = dt_Contractor.Rows[i]["State"].ToString();
                    string Description = dt_Contractor.Rows[i]["Description"].ToString();

                    int count = new Catering_Rules.ContractorDailyMangement().GetCount(" WHERE CID=" + id + " AND Year(DTime)=" + date.Year + " AND Month(DTime)=" + date.Month + " AND Day(DTime)=" + date.Day);
                    //string edit = " style='background-color:#EFEFEF;' ";
                    string state = "作业中";
                    string edit = " onclick=\"GetContractor('" + id + "','" + name + "','" + TagID + "')\" onmouseover=\"javascript:style.cursor='pointer'; this.style.background='#E3F5FF'\" onmouseout=\"this.style.background='#FFFFFF'\"";
                    if (count == 0)
                    {
                        state = "未作业";
                    }
                    result.Append("<tr " + edit + ">");
                    result.Append("<td>" + name + "&nbsp;</td>");
                    result.Append("<td>" + linkid + "&nbsp;</td>");
                    result.Append("<td>" + Tel + "&nbsp;</td>");
                    result.Append("<td>" + Add + "&nbsp;</td>");
                    result.Append("<td>" + state + "&nbsp;</td>");
                    result.Append("<td>" + Description + "&nbsp;</td>");
                    result.Append("</tr>");
                }
                dt_Contractor.Dispose();
            }
            result.Append("</table>");
            return result.ToString();
        }
    }
}